<%@ page language="java" import="com.eva.framework.dbpool.DBShell,
	java.util.regex.Matcher,
	java.util.regex.Pattern,
	com.eva.epc.common.util.CommonUtils" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	String idOrMail = request.getParameter("loginName");

	String verificationCode = request.getParameter("verificationCode");
	
	DBShell db = new DBShell();

	if(CommonUtils.isStringEmpty(idOrMail) || CommonUtils.isStringEmpty(verificationCode))
	{
		//请求信息不完整
		response.setStatus(301);
		response.setHeader("Location",basePath+"view/error.jsp?code=-1");
		response.setHeader("Connection", "close");
	}
	else
	{
		String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		Pattern p = Pattern.compile(str);
		Matcher m = p.matcher(idOrMail);
		
		String sql = "";
		if(m.matches())
			sql= "SELECT user_uid FROM missu_users where user_mail='" + idOrMail + "'";
		else
			sql= "SELECT user_uid FROM missu_users where user_uid='" + idOrMail + "'";
		String user_uid = db.querySingleItem(sql);
		
		if(user_uid == null)
		{
			//请求信息不完整,不存在用户
			response.setStatus(301);
			response.setHeader("Location",basePath+"view/error.jsp?code=-2");
			response.setHeader("Connection", "close");
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Retrieve Password</title>
<script type="text/javascript"
	src="<%=basePath%>view/js/jquery-1.9.1.js"></script>
<script type="text/javascript">
	function chk() {
		if ($("#idOrMail").val() == "") {
			alert("'Your UID or mail address' can not be empty!");
			return false;
		}

		if ($("#verificationCode").val() == "") {
			alert("'Verification Code' can not be empty!");
			return false;
		}

		if ($("#pwd").val() == "") {
			alert("'New Password' can not be empty!");
			return false;
		}

		if ($("#rePsw").val() == "") {
			alert("'Repeat New Password' can not be empty!");
			return false;
		}

		if ($("#pwd").val() != $("#rePsw").val()) {
			alert("Entered passwords differ");
			return false;
		}

		$("#retrieveForm").submit();
	}
</script>
</head>
<body style="background: #fff">
	<div style=" border:1px solid #999; height:437px; width:710px;  margin:0 auto ">
		<div style="width: 200px; float: left; height: 437px;">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				height="100%">
				<tr>
					<td align="center" valign="middle"
						style="font-family: 'Arial Black', Gadget, sans-serif; color: #d4262f; font-size: 40px;"><img
						src="images/logoklink.png" width="166" height="179"></td>
				</tr>
			</table>
		</div>
		<div style="width: 49px; float: left; height: 437px;">
			<img src="images/line.png" width="49" height="437">
		</div>

		<div id="" class=""
			style="width: 437px; height: 437px; float: left; padding-left: 15px; padding-top: 35px;">
			<form id="retrieveForm" method="post" action="retrieve.jsp">
				<dl>
					<dt
						style="font: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #575757; display:none">
						Your UID or mail address<br> <input
							style="border: #b3b3b3 solid 1px; height: 24px;" type="text"
							id="idOrMail" name="idOrMail" value="<%=idOrMail%>" />
					</dt>
				</dl>
                <div style="font:Arial, Helvetica, sans-serif; font-size:13px;color:#575757;">
                <strong style="color:#333 ;font-weight:bold; ">Reset Password</strong><br>
              Please enter a new password for your Path account in the fields below.
                </div>
                
		  <dl>
					<dt
						style="font: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #575757">
						Verification Code <br> <input
							style="border: #b3b3b3 solid 1px; height: 24px;" type="text"
							id="verificationCode" name="verificationCode"
							value="<%=verificationCode%>" />
					</dt>
				</dl>
				<dl>
					<dt
						style="font: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #575757">
						New Password <br> <input
							style="border: #b3b3b3 solid 1px; height: 24px;" type="password"
							id="pwd" name="loginPsw" />
					</dt>
				</dl>
				<dl>
					<dt
						style="font: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #575757">
						Repeat New Password <br> <input
							style="border: #b3b3b3 solid 1px; height: 24px;" type="password"
							id="rePsw" name="reLoginPsw" />
					</dt>
				</dl>
				<input style="background: url(images/botton.png) no-repeat; border:none; width: 157px; height: 41px;"
					type="text"  value=" " onClick="chk()" />
			</form>
		</div>
	</div>
</body>
</html>